package policy;

import java.util.ArrayList;
import java.util.LinkedList;

import parsers.FileParser;
import policy.branches.Branch;
import policy.nodes.Node;

public class PolicyTest {

	public static void main(String[] args) {
		ArrayList<String[]> rules = FileParser.getContents(
				"/home/sscull/workspace/Thesis/src/parsers/rules", null);
		Policy p = new Policy(rules);
		ArrayList<String[]> packets = FileParser.getContents(
				"/home/sscull/workspace/Thesis/src/parsers/log", null);
		for (int i = 0; i < packets.size(); i++) {
			boolean t = p.searchPolicy(packets.get(i), 0, p.getRoot());
			System.out.println("Rule " + i + " " + t);
		}
		// printTree(p.getRoot());
	}

	/**
	 * Performs a BFS tree traversal to print out each level of the policy.
	 */
	public static void printTree(Node n) {
		LinkedList<Node> q = new LinkedList<Node>();
		q.add(n);
		while (!q.isEmpty()) {
			Node s = q.removeFirst();
			if (s == null)
				continue;
			System.out.print(s.getType() + ":\t");
			ArrayList<Branch> branches = s.getBranches();
			for (Branch b : branches) {
				System.out.print(b.getValue() + "\t");
				q.add(b.getNode());
			}
			System.out.println();
		}

	}
}
